import request from "@/utils/request";
import type { Message } from "@/types/message";

export interface HistoryQuery {
  skip?: number;
  limit?: number;
  keyword?: string;
  start_date?: string;
  end_date?: string;
  source?: "internal" | "external";
}

export interface MessageDTO {
  id: number;
  role: Message["role"];
  content: string;
  status?: Message["status"];
}

export interface ConversationDTO {
  id: number | string;
  session_id?: string;
  title: string;
  messages?: MessageDTO[];
  created_at: string;
  updated_at: string;
  source?: "internal" | "external";
}

export interface ConversationListResponse {
  total: number;
  conversations: ConversationDTO[];
}

export interface ConversationDeleteResponse {
  message: string;
  session_id?: string;
  title?: string;
}

export const getConversationList = (
  params: HistoryQuery
): Promise<ConversationListResponse> => {
  return request.get("/history/conversations", { params });
};

export const getConversationDetail = (
  conversationId: string | number
): Promise<ConversationDTO> => {
  return request.get(`/history/conversations/${conversationId}`);
};

export const removeConversation = (
  conversationId: string | number
): Promise<ConversationDeleteResponse> => {
  return request.delete(`/history/conversations/${conversationId}`);
};
